package com.example.interceptor;


import android.content.Context;
import android.text.TextUtils;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.example.constants.Constants;
import com.example.event.OpenDialogEvent;

import org.greenrobot.eventbus.EventBus;

@Interceptor(priority = 1)
public class UseInterceptor implements IInterceptor{

    private Context context;

    @Override
    public void process(final Postcard postcard, final InterceptorCallback callback) {
        if(TextUtils.equals(Constants.FIND_ACTIVITY_URL,postcard.getPath())){
            EventBus.getDefault().post(new OpenDialogEvent(postcard,callback));
//            AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
//            alertDialog.setTitle("请做出选择").setIcon(R.mipmap.ic_launcher)
//                    .setMessage("确定或者取消");
//            alertDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                @Override
//                public void onClick(DialogInterface dialog, int which) {
//                    callback.onInterrupt(null);
//                }
//            });
//            alertDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                @Override
//                public void onClick(DialogInterface dialog, int which) {
//                    callback.onContinue(postcard);
//                }
//            });
//            alertDialog.create().show();
//            callback.onInterrupt(null);
        }else {
            callback.onContinue(postcard);
        }
    }

    @Override
    public void init(Context context) {
        this.context = context;
    }
}
